package fei.yuzhi.com.loveflowers.fragment.classifyFragment;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import fei.yuzhi.com.loveflowers.R;

/**
 * Created by Administrator on 2016/10/8.
 */
public class ClassifyListLeftAdapter extends BaseAdapter{
    private List<String> list;
    private Context context;
    private int mSelect=0;

    public ClassifyListLeftAdapter(List<String> list,Context context){
        this.list=list;
        this.context=context;
    }
    public void changeSelected(int positon){ //刷新方法
        if(positon != mSelect){
            mSelect = positon;
        }

    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            convertView=LayoutInflater.from(context).inflate(R.layout.listview_classifyall_adapter,null);
            holder=new ViewHolder();
            holder.tv_classifylistview= (TextView) convertView.findViewById(R.id.tv_classifylistview);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tv_classifylistview.setText(list.get(position));
//        convertView.setBackgroundResource(R.drawable.classifylist_selector);
        if(mSelect==position){
            convertView.setBackgroundResource(R.color.white);  //选中项背景
        }else {
            convertView.setBackgroundResource(R.color.classifylist_back);
        }
        return convertView;
    }
    static class ViewHolder{
        TextView tv_classifylistview;
    }
}
